package com.example.springcloud.storage.service.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * 库存 TCC 服务接口
 */
@LocalTCC
public interface StorageTCCService {

    /**
     * Try 阶段：冻结库存
     */
    @TwoPhaseBusinessAction(
        name = "storageTCC",
        commitMethod = "confirm",
        rollbackMethod = "cancel"
    )
    void tryDeduct(@BusinessActionContextParameter(paramName = "productId") Long productId,
                   @BusinessActionContextParameter(paramName = "count") Integer count);

    /**
     * Confirm 阶段：确认扣减
     */
    boolean confirm(BusinessActionContext context);

    /**
     * Cancel 阶段：释放冻结的库存
     */
    boolean cancel(BusinessActionContext context);
}

